@model QueriesIndexViewModel

<h1>@RenderTitleSegments(T["Queries"])</h1>

<nav class="admin-toolbar">
    <ul class="navbar-nav mr-auto">
        <li class="nav-item">
            <button type="button" class="btn btn-primary" role="button" data-toggle="modal" data-target="#modalAddQuery">@T["Add Query"]</button>
        </li>
    </ul>
        <form asp-action="Index" method="get" class="form-inline my-2 my-lg-0">
            <input id="search-box" asp-for="Options.Search" class="form-control mr-sm-2" type="text" placeholder="@T["Search"]" autofocus="autofocus">
            <button type="submit" class="btn btn-secondary">@T["Search"]</button>
        </form>
</nav>

<form asp-action="Index"> @* the form is nessecary to generate and antiforgery token for the delete action *@

    @if (Model.Queries.Any())
    {
        <ul class="list-group">
            @foreach (var entry in Model.Queries)
            {
                <li class="list-group-item">
                    @await DisplayAsync(entry.Shape)
                </li>
            }
        </ul>
    }
    else
    {
        <div class="alert alert-info" role="alert">
            @T["<strong>Nothing here!</strong> There are no queries for the moment."]
        </div>
    }
</form>

@await DisplayAsync(Model.Pager)

<!-- Modal -->
<div class="modal fade" id="modalAddQuery" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">@T["Available Query Types"]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="card-columns">
                    @if (!Model.QuerySourceNames.Any())
                    {
                        <h3>@T["You need to enable a feature which provides a query source."]</h3>
                    }

                    @foreach (var source in Model.QuerySourceNames)
                    {
                        Orchard.DisplayManagement.IShape shape = New.Query_Link(Name: source);
                        shape.Metadata.Alternates.Add("Query_Link__" + source);

                        @await DisplayAsync(shape)
                    }
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">@T["Cancel"]</button>
            </div>
        </div>
    </div>
</div>